#include<stdio.h>
#include<errno.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>


int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        //子进程
        int cnt = 5;
        while(cnt)
        {
            printf("我是一个子进程, pid: %d, ppid: %d\n", getpid(), getppid());
            sleep(1);
            cnt--;
        }
        exit(0);
    }

    sleep(10);
    //父进程
    //pid_t rid = wait(NULL);
    pid_t rid = waitpid(id, NULL, 0);
    if(rid > 0)
    {
        printf("wait success, rid: %d\n", rid);//rid
    }
    sleep(10);

    return 0;
}
